//
//  TSInviteViewController.swift
//  TSProfitProject
//
//  Created by TmmmS on 2019/11/6.
//  Copyright © 2019 TMS. All rights reserved.
//

import UIKit

class TSInviteViewController: TSBaseViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.navigationController?.delegate = self;
        
        configViews()
    }

    @objc func inviteAction() {
        
        navigationController?.pushViewController(TSInvationViewController(), animated: true)
    }

    deinit {
        self.navigationController?.delegate = nil
    }
}

extension TSInviteViewController {
    
    func configViews() {
        
        let container = UIView.init()
        container.backgroundColor = WHITE_COLOR
        self.view.addSubview(container)
        container.snp.makeConstraints { (make) in
            make.left.right.centerY.equalToSuperview()
        }
        
        let bgImg = UIImageView.init(image: UIImage(named: "invite_bg"))
        container.addSubview(bgImg)
        bgImg.snp.makeConstraints { (make) in
            make.centerX.top.equalToSuperview()
            make.size.equalTo(CGSize(width: 317*T_ScreenScale(), height: 364*T_ScreenScale()))
        }
        
        let inviteBtn = UIButton.init(type: .system)
        inviteBtn.setTitle("立即邀请", for: .normal)
        inviteBtn.setTitleColor(WHITE_COLOR, for: .normal)
        inviteBtn.titleLabel?.font = UIFont.systemFont(ofSize: 18, weight: .medium)
        inviteBtn.backgroundColor = BASE_PURPLE_COLOR
        inviteBtn.layer.cornerRadius = 24
        inviteBtn.layer.masksToBounds = true
        inviteBtn.addTarget(self, action: #selector(inviteAction), for: .touchUpInside)
        container.addSubview(inviteBtn)
        inviteBtn.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(bgImg.snp_bottom).offset(30)
            make.size.equalTo(CGSize(width: SCREEN_WIDTH*0.61, height: 48))
            
            make.bottom.equalTo(-0.001)
        }
    }
}

// MARK: - UINavigationControllerDelegate
extension TSInviteViewController : UINavigationControllerDelegate {
    func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
        let isShowHomePage = viewController.isKind(of: TSInviteViewController.self)
        self.navigationController?.setNavigationBarHidden(isShowHomePage, animated: false)
    }
}

